/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.ucv.daos;

import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import pe.edu.ucv.entidades.Area;

/**
 *
 * @author Administrator
 */
@Stateless
@LocalBean
public class AreaDaos {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @PersistenceContext EntityManager em;
   public void crear(Area area){
       em.persist(area);
   } 
   public void actualizar(Area area){
       em.merge(area);
   }
   public void guardar(Area area){
       if(area.getId()==null){
           crear(area);
       }else{
           actualizar(area);
       }
   }
   public void borrar(Integer id){
       Area area=em.find(Area.class, id);
       em.remove(area);
   }
   public List<Area> listarTodas(){
       return em.createNamedQuery("Area.findAll",Area.class).getResultList();
   }
   public List<Area> buscarPordescripcion(String nombre){
       return em.createNamedQuery("Area.findByDescripcion",Area.class)
               .setParameter("descripcion", nombre).getResultList();
   }
}
